package com.avcdata.aoscustommade.presenter;

import com.avcdata.aoscustommade.bean.BaseResponseBean;
import com.avcdata.aoscustommade.bean.GetVerificationCodeBean;
import com.avcdata.aoscustommade.bean.VerifyNoteBean;
import com.avcdata.aoscustommade.bean.VerifyPhotoNumberBean;
import com.avcdata.aoscustommade.main.BaseCallBack;
import com.avcdata.aoscustommade.main.LoginBaseCallBack;
import com.avcdata.aoscustommade.model.LoginActivityModel;
import com.avcdata.aoscustommade.view.LoginActivityView;

/**
 * Created by zyh on 2017/6/5.
 */

public class LoninActivityPresenter {
    private final LoginActivityView loginActivityView;
    private final LoginActivityModel loginActivityModel;

    public LoninActivityPresenter(LoginActivityView loginActivityView, LoginActivityModel loginActivityModel) {
        this.loginActivityView = loginActivityView;
        this.loginActivityModel = loginActivityModel;
    }

    /**
     * 获取手机验证码
     * @param userAccount  手机号
     */
    public void loadCode(String userAccount){
        loginActivityModel.loadCode(userAccount, new BaseCallBack(){

            @Override
            public void onSuccess(Object object) {
                loginActivityView.loadCodeSuccess((GetVerificationCodeBean) object);
            }

            @Override
            public void onFailure() {
                loginActivityView.loadCodeFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 校验手机号
     * @param userAccount 手机号
     */
    public void loadCheackAccount(String userAccount){
        loginActivityModel.loadCheackAccount(userAccount, new BaseCallBack(){

            @Override
            public void onSuccess(Object object) {
                loginActivityView.loadCheackAccountSuccess((VerifyPhotoNumberBean) object);
            }

            @Override
            public void onFailure() {
                loginActivityView.loadCheackAccountFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }

    /**
     * 获取手机key
     * @param account
     */
    public void loadGetSecreKey(String account){
        loginActivityModel.loadGetSecreKey(account, new LoginBaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                loginActivityView.loadGetSecreKeySuccess((GetVerificationCodeBean) object);
            }

            @Override
            public void onFailure() {
                loginActivityView.loadGetSecreKeyOnFailure();
            }

            @Override
            public void onFailure(BaseResponseBean bean) {
                loginActivityView.loadGetSecreKeyOnFailure(bean);
            }

        });
    }

    /**
     * 验证手机验证码
     * @param userAccount
     * @param userTextCode
     */
    public void loadCheckCode(String userAccount, String userTextCode) {
        loginActivityModel.loadCheckCode(userAccount, userTextCode, new BaseCallBack(){
            @Override
            public void onSuccess(Object object) {
                loginActivityView.loadCheckCodeSuccess((VerifyNoteBean)object);
            }

            @Override
            public void onFailure() {
                loginActivityView.loadCheackCodeFailure();
            }

            @Override
            public void onFailure(Throwable throwable) {

            }
        });
    }
}
